#include <Ape/Serialization/ISink.h>

#include <Ape/Collections/Array.h>
#include <Ape/Serialization/ISerializeable.h>

namespace Ape {
	namespace Serialization {
		size_t ISink::SubmergeRaw (const unsigned char* pBytes, size_t size) {
			Ape::Collections::Array<unsigned char> buff (size, '\0');
			for (size_t i = 0; i < size; i++) {
				buff[i] = pBytes[i];
			}
			return SubmergeBytes (buff);
		}
		
		void ISink::EmergeRaw (unsigned char* pData, size_t size) {
			/*
			 * TODO: we should throw an Ape::Serialization::SerializationException here
			 * if the given size and buffers are not equal
			 */
			Ape::Collections::Array<unsigned char> buff (size, '\0');
			EmergeBytes (buff);
			for (size_t i = 0; i < size; i++) {
				pData[i] = buff[i];
			}
		}
		
		void ISink::Submerge (const ISerializeable& object) {
			//printf("void ISink::Submerge (const ISerializeable& object)\n");
			object.Sink (this);
		}
		void ISink::Emerge (ISerializeable& object) {
			//printf("void ISink::Emerge (ISerializeable& object)\n");
			object.Unsink (this);
		}
		
		void ISink::Submerge (const ISerializeable* object) {
			//printf("void ISink::Submerge (const ISerializeable* object)\n");
			//object->Sink (this);
		}
		void ISink::Emerge (ISerializeable* object) {
			// TODO: here we should instantiate a new object on the heap
			// 
			
			//printf("void ISink::Emerge (ISerializeable* object)\n");
			//object->Unsink (this);
		}
		
	}
}
